package daily;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class LockTest {

	public static void main(String[] args) {
		
		final Output output=new Output();
		
		new Thread(new Runnable(){

			@Override
			public void run() {
				for(int i=0;i<10;i++){
					output.output("xxxxxxxxxxxxxxxxxxxxx");
				}
			}
			
		}).start();
		
		
		new Thread(new Runnable(){

			@Override
			public void run() {
				for(int i=0;i<10;i++){
					output.output("YYYYYYYYYYYYYYYYYYYYY");
				}
			}
			
		}).start();
	}
	
	static class Output{
		Lock lock=new ReentrantLock();
		public  void output(String name){
			
			lock.lock();
			int lenth=name.length();
			try {
				for(int i=0;i<lenth;i++){
					System.out.print(name.charAt(i));
				}
				System.out.println();
			}finally{
				lock.unlock();
			}
			
		}
	}

}
